package com.hoperun.checkcloth.util;


import java.security.MessageDigest;

public class MD5Encrypt {

    public static String MD5(String s) {

        char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            if (s != null && !"".equals(s.trim())) {
                byte[] strTemp = s.getBytes();
                MessageDigest mdTemp = MessageDigest.getInstance("MD5");
                mdTemp.update(strTemp);
                byte[] md = mdTemp.digest();
                char[] str = new char[md.length * 2];
                int k = 0;
                for (byte b : md) {
                    str[k++] = hexDigits[b >>> 4 & 0xf];
                    str[k++] = hexDigits[b & 0xf];
                }
                return new String(str);
            } else {
                return "";
            }
        } catch (Exception e) {
            return null;
        }

    }

}
